var fs = require("fs");
// 在文件头部引入 Node.js 中的 path 模块
const path = require('path');
const { remote } = require('electron')
const BrowserWindow = remote.BrowserWindow;

console.log("-----")
fs.readFile("mock/key.json",(err,data)=>{
    console.log(data)
})

window.onload = () => {
    var btnLoad  = document.querySelector("#btnLoadJson")
    var txtJson  = document.querySelector("#txtJson")
    var contentDom  = document.querySelector("#content")
    console.log(".....!")
    btnLoad.onclick = ()=>{
        console.log("clicked!")
        fs.readFile("mock/key.json",(err,data)=>{
            if(err) {
                console.log(err);
                return;
            }
            console.log(data);
            txtJson.innerHTML = data;
        })
    }

    btnAdd.onclick = ()=>{
        const mainWindow = new BrowserWindow({
            width:800,
            height: 600,
           webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true,
          }
        })
        console.log(path.join(__dirname,'new.html'))
        //加载本地页面
        mainWindow.loadFile(path.join(__dirname,'new.html'))
    }

    contentDom.ondragenter = contentDom.ondragover = ()=>{
        console.log("contentDom.ondragover....");
        return false;
    }

    contentDom.ondrop =(e)=>{
        var filePath  = e.dataTransfer.files[0].path
        console.log(filePath)
        fs.readFile(filePath,(err,data)=>{
            if(err) {
                console.log(err);
                return;
            }
            console.log(data);
            txtJson.innerHTML = data;
        })
    }
}

